package lab.cadl.lirui.markdown.core.utils

import org.scilab.forge.jlatexmath.DefaultTeXFont
import org.scilab.forge.jlatexmath.TeXConstants
import org.scilab.forge.jlatexmath.TeXFormula
import org.scilab.forge.jlatexmath.cyrillic.CyrillicRegistration
import org.scilab.forge.jlatexmath.greek.GreekRegistration
import java.awt.Color
import java.io.File


object LatexUtils {
    const val SCALE: Int = 4

    init {
        DefaultTeXFont.registerAlphabet(CyrillicRegistration())
        DefaultTeXFont.registerAlphabet(GreekRegistration())
    }

    fun saveFormulaToImage(formulaText: String, targetFile: File) {
        val formula = TeXFormula(formulaText)
        formula.createPNG(TeXConstants.STYLE_DISPLAY, (12 * SCALE).toFloat(), targetFile.toString(), Color.WHITE, Color.BLACK)
    }
}